package com.wangx1n.boobey.service;

import com.google.gson.Gson;
import com.wangx1n.boobey.dao.UserMapper;
import com.wangx1n.boobey.entity.User;
import com.wangx1n.boobey.entity.UserExample;
import com.wangx1n.boobey.util.ApiResult;
import com.wangx1n.boobey.util.CodeMsg;
import com.wangx1n.boobey.util.WxTool;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author wangxin
 * @create 2020-06-13 0:13
 */
@Service
public class UserService {
    @Resource
    UserMapper userMapper;
    public String Login(User user,String code){
        Gson gson = new Gson();
        if(code==null||code.equals("")){
            return gson.toJson(ApiResult.error(CodeMsg.NO_USER));
        }
        String openid = WxTool.code2Session(code);
        if(openid==null){
            userMapper.insertSelective(user);
            return gson.toJson(ApiResult.success("注册成功",0));
        }
        return gson.toJson(ApiResult.success("登录成功",0));
    }
}
